﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smrf.NodeXL.Layouts;
using Smrf.NodeXL.Core;
using System.Drawing;

namespace pptGraphCreatorAddIn
{
    public static class GraphLayoutFactory
    {
        /// <summary>
        /// This methods lays out a graph and returns the result
        /// </summary>
        /// <param name="graph">The graph to layout</param>
        /// <param name="layout">The type of the layout to apply</param>
        /// <returns>Layed out graph</returns>
        public static IGraph ApplyLayout(IGraph graph, GraphLayout layout,Rectangle rec)
        {
            ILayout LayoutToUse = GetLayoutFromEnum(layout);

            LayoutToUse.LayOutGraph(graph, new LayoutContext(rec));
            return graph;
        }

        

        public static IGraph ApplyLayout(IGraph graph, String layout, Rectangle rec)
        {
            ILayout LayoutToUse = GetLayoutFromName(layout);

            if (LayoutToUse == null)
            {
                return null;
            }

            LayoutToUse.LayOutGraph(graph, new LayoutContext(rec));
            return graph;
        }


        public static ILayout GetLayoutFromEnum(GraphLayout layout)
        {
            ILayout LayoutToUse;
            switch (layout)
            {
                case GraphLayout.CircleLayout:
                    LayoutToUse = new CircleLayout();
                    break;
                case GraphLayout.FruchtermanReingoldLayout:
                    LayoutToUse = new FruchtermanReingoldLayout();
                    break;
                case GraphLayout.GridLayout:
                    LayoutToUse = new GridLayout();
                    break;
                case GraphLayout.HarelKorenFastMultiscaleLayout:
                    LayoutToUse = new HarelKorenFastMultiscaleLayout();
                    break;
                case GraphLayout.PolarLayout:
                    LayoutToUse = new PolarLayout();
                    break;
                case GraphLayout.RandomLayout:
                    LayoutToUse = new RandomLayout();
                    break;
                case GraphLayout.SinusoidHorizontalLayout:
                    LayoutToUse = new SinusoidHorizontalLayout();
                    break;
                case GraphLayout.SinusoidVerticalLayout:
                    LayoutToUse = new SinusoidVerticalLayout();
                    break;
                case GraphLayout.SpiralLayout:
                    LayoutToUse = new SpiralLayout();
                    break;
                case GraphLayout.SugiyamaLayout:
                    LayoutToUse = new SugiyamaLayout();
                    break;
                default:
                    LayoutToUse = new RandomLayout();
                    break;
            }
            return LayoutToUse;
        }

        public static ILayout GetLayoutFromName(string LayoutName)
        {
            switch (LayoutName)
            {
                case "Circle":
                    {
                        CircleLayout cl = new CircleLayout();
                        return cl;
                    }
                case "FruchtermanReingold":
                    {
                        FruchtermanReingoldLayout FRL = new FruchtermanReingoldLayout();
                        return FRL;
                    }
                case "Grid":
                    {
                        GridLayout gl = new GridLayout();
                        return gl;
                    }
                case "Polar":
                    {
                        PolarLayout pl = new PolarLayout();
                        return pl;
                    }
                case "Random":
                    {
                        RandomLayout rl = new RandomLayout();
                        return rl;
                    }
                case "Sinusoid":
                    {
                        SinusoidHorizontalLayout shl = new SinusoidHorizontalLayout();
                        return shl;
                    }
                case "Spiral":
                    {
                        SpiralLayout sl = new SpiralLayout();
                        return sl;
                    }
                case "Sugiyama":
                    {
                        SugiyamaLayout sgl = new SugiyamaLayout();
                        return sgl;
                    }
                default:
                    return null;
            }
        }
    }
}
